<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$intBT = (int)$_data["Bet_Type"];
$intGID = (int)$_data["GambleID"];
$intNum = (int)$_data["intNumber"];
$flOdds = (float)$_data["Odds"];
//$intSpecialNumType = (int)$_data["SpecialNumType"];

if($intBT < 1 || $intGID < 1 || $intLID < 1){
	$GLOBALS["errormessage"] = "Data Error!!";
	$GLOBALS["errorhidden"] = "\nBetType:".$intBT."\nGambleID:".$intGID."\nLottoID:".$intLID."\nLine:".__LINE__."\nPage:".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}

$flOdds = ConvertOdds($intLType, $intBT, $flOdds);

$intAN = $_arrGLineNumToApointNum[$intLID][$intBT][$intNum];
if($intAN == null)$intAN = 0;

include_once(__Common_Path."/gambletype/GambleType1_".$intLID.".inc.php");
$A_AllOdds = $_arrGambleTypeAllOdds[$intBT][$intAN];
include_once(__Common_Path."/gambletype/GambleType".$_data["GameType"]."_".$intLID.".inc.php");
$preAllOdds = $_arrGambleTypeAllOdds[$intBT][$intAN];
$flOdds -= ($preAllOdds - $A_AllOdds)/2;

if($flOdds < 0)$flOdds = 0;
if($intBT == 1 || $intBT == 28){
	if($intBT == 28){	//調整的是特碼 B 賠率
		if($_arrBetParam[28][$intAN]["maxOdds"] < $flOdds)$flOdds = $_arrBetParam[28][$intAN]["maxOdds"];
	}else{
		if($_arrBetParam[1][$intAN]["maxOdds"] < $flOdds)$flOdds = $_arrBetParam[1][$intAN]["maxOdds"];
	}
}else{
	if($_arrBetParam[$intBT][$intAN]["maxOdds"] < $flOdds)$flOdds = $_arrBetParam[$intBT][$intAN]["maxOdds"];
}

$intNumber = 0;
$intBT = (int)$intBT;
$arrBT = array($intBT);
$arrBTOdds[$intBT] = $flOdds;

PMA_mysql_query("BEGIN", $_ConnMaster);
switch($intBT){
	case 12:
	case 13:
	case 27:
	case 16:
	case 2:
	case 3:
	case 5:
	case 6:
		$intNumber = (int)$intNum;
		$intNumber2 = ($intNumber % 10 == 1)?($intNumber - 1):($intNumber + 1);
		//輸入單分或大賠率
		$OtherOdds = $A_AllOdds - $flOdds;
		$OtherOdds = ConvertOdds($intLType, $intBT, $OtherOdds);
		if(!$intOID = InsertBetTypeOdds($intGID, $intLID, $intBT, $intNumber, $flOdds, 0, $_SESSION["Admin_Info"] -> Account)){
			@PMA_mysql_query("ROLLBACK", $_ConnMaster);
			ErrMsgOutputHTML("Error", "", 1);
		}
		if(!UpdateTodayGame($intGID, $intLID, $intBT, $intNumber, $intOID, $flOdds, ", tolJumpStake = 0")){
			@PMA_mysql_query("ROLLBACK", $_ConnMaster);
			ErrMsgOutputHTML("Error", "", 1);
		}

		//輸入雙分或小盤賠率
		if(!$intOID2 = InsertBetTypeOdds($intGID, $intLID, $intBT, $intNumber2, $OtherOdds, 0, $_SESSION["Admin_Info"] -> Account)){
			@PMA_mysql_query("ROLLBACK", $_ConnMaster);
			ErrMsgOutputHTML("Error", "", 1);
		}
		if(!UpdateTodayGame($intGID, $intLID, $intBT, $intNumber2, $intOID2, $OtherOdds, ", tolJumpStake = 0")){
			@PMA_mysql_query("ROLLBACK", $_ConnMaster);
			ErrMsgOutputHTML("Error", "", 1);
		}
		break;

	case 1:
	case 28:
		$arrBT = array(1, 28);
		//$flOdds = $flOdds - (($intSpecialNumType == 2 || $intSpecialNumType == 4)?5:0);
		$flABGapOdds = $_flABGapOdds;
		if($intBT == 28){	//調整的是特碼 B 賠率
			$arrBTOdds[28] = $flOdds;
			if($flOdds <= $_flBOdds2)$flABGapOdds = $_flABGapOdds2;
			if($flOdds <= $_flBOdds3)$flABGapOdds = $_flABGapOdds3;
			$arrBTOdds[1] = $flOdds - $flABGapOdds;
			if($_arrBetParam[1][$intAN]["maxOdds"] < $arrBTOdds[1])$arrBTOdds[1] = $_arrBetParam[1][$intAN]["maxOdds"];

		}else{	//調整的是特碼 A 賠率
			$arrBTOdds[1] = $flOdds;
			if($flOdds <= $_flAOdds2)$flABGapOdds = $_flABGapOdds2;
			if($flOdds <= $_flAOdds3)$flABGapOdds = $_flABGapOdds3;
			$arrBTOdds[28] = $flOdds + $flABGapOdds;
			if($_arrBetParam[28][$intAN]["maxOdds"] < $arrBTOdds[28])$arrBTOdds[28] = $_arrBetParam[28][$intAN]["maxOdds"];
		}
	default:
		foreach($arrBT as $intBTT){
			if(!$intOID = InsertBetTypeOdds($intGID, $intLID, $intBTT, $intNum, $arrBTOdds[$intBTT], 0, $_SESSION["Admin_Info"] -> Account)){
				@PMA_mysql_query("ROLLBACK", $_ConnMaster);
				ErrMsgOutputHTML("Error", "", 1);
			}
			if(!UpdateTodayGame($intGID, $intLID, $intBTT, $intNum, $intOID, $arrBTOdds[$intBTT], ", tolJumpStake = 0")){
				@PMA_mysql_query("ROLLBACK", $_ConnMaster);
				ErrMsgOutputHTML("Error", "", 1);
			}
		}
		break;
} //switch($intBT){
@PMA_mysql_query("COMMIT", $_ConnMaster);
//產生 TodayGame File
foreach($arrBT as $intBTT){
	if(!MakeTodayGameFile($intLID, $intBTT))ErrMsgOutputHTML("Error", "", 1);
}
$strLog = "樂透種類：".$intLID."\n";
$strLog .= "操盤序號：".$intGID."\n";
$strLog .= "下注種類：".$intBT."\n";
$strLog .= "賠率序號：".$intOID."：".$intOID2."\n";
$strLog .= "賠率：".$flOdds."：".$OtherOdds."\n";
$strLog .= "號碼：".$intNum."\n";
AddData_Log($_SESSION["Admin_Info"] -> ID, "更改賠率", $strLog);
/*=================================================================*/
header("Cache-Control: no-store, no-cache, must-revalidate");	  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");															  // HTTP/1.0
?><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript">
<!--
parent.RefreshType();
//-->
</script>